﻿namespace System.Extensions
{
    public static class JsonOpt
    {
        public static System.Text.Json.JsonSerializerOptions UnicodeRangesAll
        {
            get { return DefaultOptions(); }
        }

        public static System.Text.Json.JsonSerializerOptions IgnoreNullValues
        {
            get
            {
                System.Text.Json.JsonSerializerOptions options = DefaultOptions();
                options.IgnoreNullValues = true;
                return options;
            }
        }

        public static System.Text.Json.JsonSerializerOptions DefaultOptions(string dateTimeFormat = "yyyy-MM-dd HH:mm:ss")
        {
            //JsonSerializerOptions Options = new JsonSerializerOptions() { Encoder = System.Text.Encodings.Web.JavaScriptEncoder.Create(UnicodeRanges.All), PropertyNamingPolicy = JsonNamingPolicy.CamelCase, WriteIndented = true };
            System.Text.Json.JsonSerializerOptions options = new System.Text.Json.JsonSerializerOptions() { Encoder = System.Text.Encodings.Web.JavaScriptEncoder.Create(System.Text.Unicode.UnicodeRanges.All) };
            options.Converters.Add(new DateTimeConverterUsingDateTimeParse(dateTimeFormat));
            return options;
        }
    }
}
